package org.msfj.toilets.socket.udp;

import org.msfj.toilets.config.ToiletConfig;
import org.msfj.toilets.socket.DataHandler;
import org.tio.core.Node;
import org.tio.core.udp.UdpPacket;
import org.tio.core.udp.intf.UdpHandler;

import java.net.DatagramSocket;

/**
 * @Description:
 * @User: Administrator
 * @Date: 2018/10/4 0004
 */
public class TioUdpHandler implements UdpHandler {

    private ToiletConfig toiletConfig;

    public TioUdpHandler (ToiletConfig toiletConfig){
        this.toiletConfig = toiletConfig;
    }

    @Override
    public void handler(UdpPacket udpPacket, DatagramSocket datagramSocket) {
        byte[] bytes = udpPacket.getData();
        int size = udpPacket.getData().length;
        Node remote = udpPacket.getRemote();
        DataHandler.handler(bytes, size, remote,"UDP",toiletConfig);
    }
}
